package com.gaussian.property.admin.module.biz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gaussian.property.admin.module.biz.service.ProjectMonitorService;
import com.gaussian.property.admin.module.biz.vo.monitor.PageQueryProjectMonitorRequest;
import com.gaussian.property.admin.module.biz.vo.monitor.ProjectMonitorForm;
import com.gaussian.property.module.biz.entity.MonitorIndicator;
import com.gaussian.property.module.biz.entity.ProjectMonitor;
import com.gaussian.property.module.biz.service.IMonitorIndicatorService;
import com.gaussian.property.module.biz.vo.projectchecktable.PageQueryProjectTableRequest;
import com.gaussian.property.module.biz.vo.projectchecktable.ProjectCheckTableDetail;
import com.songqi.common.core.domain.R;
import com.songqi.common.core.domain.page.PageDataInfo;
import com.songqi.common.core.validationgroup.EditGroup;
import com.songqi.common.web.request.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.groups.Default;
import java.util.List;

/**
 * @description:
 * @author: songqi(13776346982)
 * @date: 2024/9/29 21:37
 */
@Api(tags = "项目总结(监控)配置")
@Validated
@RestController
@RequestMapping("projectMonitor/")
public class ProjectMonitorController extends BaseController {

    @Resource
    private IMonitorIndicatorService iMonitorIndicatorService;
    @Resource
    private ProjectMonitorService projectMonitorService;

    @ApiOperation("分页查询项目监控指标")
    @GetMapping("pageQueryProjectMonitor")
    public R<PageDataInfo<ProjectMonitor>> pageQueryProjectTable(PageQueryProjectMonitorRequest queryRequest){
        IPage<ProjectMonitor> pageData = projectMonitorService.pageQueryProjectMonitor(queryRequest);
        return getReturnDataTableInfo(pageData);
    }


    @ApiOperation("列出所有监控指标")
    @GetMapping("listMonitorIndicator")
    public R<List<MonitorIndicator>> listMonitorIndicator(){
        QueryWrapper<MonitorIndicator> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("CONVERT(monitor_indicator_id, UNSIGNED)");
        return success(iMonitorIndicatorService.list(queryWrapper));
    }

    @ApiOperation("新增项目监控指标")
    @PostMapping("addProjectMonitor")
    public R<Void> addProjectMonitor(@RequestBody @Validated(Default.class) ProjectMonitorForm projectMonitor){
        projectMonitorService.addProjectMonitor(projectMonitor);
        return success();
    }

    @ApiOperation("查看项目监控指标")
    @GetMapping("getById/{projectMonitorId}")
    public R<ProjectMonitorForm> getById(@PathVariable String projectMonitorId){
        return success(projectMonitorService.getById(projectMonitorId));
    }

    @ApiOperation("编辑项目监控指标")
    @PostMapping("editProjectMonitor")
    public R<Void> editProjectMonitor(@RequestBody @Validated({EditGroup.class, Default.class}) ProjectMonitorForm projectMonitor){
        projectMonitorService.editProjectMonitor(projectMonitor);
        return success();
    }

    @ApiOperation("启用、停用项目总结配置。返回更新后的状态。1：启用，0：停用")
    @PutMapping("changeStatus/{projectMonitorId}")
    public R<Integer> changeStatus(@PathVariable String projectMonitorId){
        return success(projectMonitorService.changeStatus(projectMonitorId));
    }


    @ApiOperation("删除项目每日总结配置")
    @DeleteMapping("deleteProjectMonitor/{projectMonitorId}")
    public R<Void> deleteProjectMonitor(@PathVariable String projectMonitorId){
        projectMonitorService.deleteProjectMonitor(projectMonitorId);
        return success();
    }

}
